import PubSub from 'pubsub-js';

// export interface handler<T> {
//   (eventName: any, data: T): void;
// }

export default class EventHub {
  constructor(props) {
  }

  static on(
    eventName,
    handler,
    { eventNameOnly = true } = {},
  ) {
    if (eventNameOnly) {
      PubSub.subscribe(`${eventName}${document.location.search}`, handler);
    } else {
      PubSub.subscribe(`${eventName}`, handler);
    }
  }

  static emit(eventName, data, { eventNameOnly = true } = {}) {
    if (eventNameOnly) {
      PubSub.publish(`${eventName}${document.location.search}`, data);
    } else {
      PubSub.publish(`${eventName}`, data);
    }
  }

  static off(eventName, target) {
    return true;
  }

  static list(){
    return PubSub;
  }
}
